<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改内容标签')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tag-edit" th:object="${articleTag}">
            <input name="tagId" th:field="*{tagId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">父标签ID：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="parentTagId" type="hidden" th:field="*{parentTagId}" />
                        <input class="form-control" type="text" onclick="selectTagTree()" id="treeName" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">分类展示：<span th:text="${articleTag.showMain}"></span></label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="showMain" th:checked="${articleTag.showMain == 1 ? true : false}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">首页推荐：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="recom" th:checked="${articleTag.recom == 1 ? true : false}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">标签介绍：</label>
                <div class="col-sm-8">
                    <textarea name="introduction" class="form-control" th:field="*{introduction}"  rows="10"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "wenyanwen/tag";
        $("#form-tag-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $('#form-tag-edit').serializeArray();
                var showMain = $("input[id='showMain']").is(':checked') == true ? 1 : 0;
            	data.push({"name": "showMain", "value": showMain});
            	var recom = $("input[id='recom']").is(':checked') == true ? 1 : 0;
            	data.push({"name": "recom", "value": recom});
                $.operate.save(prefix + "/edit", data);
            }
        }

        /*内容标签-新增-选择父部门树*/
        function selectTagTree() {
            var options = {
                title: '内容标签选择',
                width: "380",
                url: prefix + "/selectTagTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#treeId").val(body.find('#treeId').val());
               $("#treeName").val(body.find('#treeName').val());
               layer.close(index);
        }
    </script>
</body>
</html>